package br.com.advance.automacao.web.administrativo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
import org.springframework.beans.factory.annotation.Autowired;

import br.com.advance.automacao.model.Turno;
import br.com.advance.automacao.services.TurnoService;
import br.com.advance.automacao.web.utils.BaseBean;

@ManagedBean
@ViewScoped
public class CadastroTurnoMBean extends BaseBean {

	/**
	 *
	 */
	private static final long serialVersionUID = 4180491670576658298L;

	private static final Logger logger = Logger.getLogger(CadastroTurnoMBean.class);

	private List<Turno> listTurno;

	@Autowired
	private TurnoService turnoService;

	public void initialize() {
		logger.info("initialize...");
		listTurno = turnoService.buscarTodos();
	}

	protected boolean verificaUsuarioLogado() {
		return true;
	}


	public void abreEdicaoTurno(Turno item) {
		Map<String, Object> options = new HashMap<String, Object>();
		options.put("resizable", false);
		options.put("modal", true);
		options.put("closeable", false);
		options.put("includeViewParams", true);

		Map<String, List<String>> params = new HashMap<String, List<String>>();
		List<String> values = new ArrayList<String>();
		values.add(String.valueOf(item.getId()));
		params.put("idTurno", values);

		RequestContext.getCurrentInstance().openDialog("editarTurno", options, params);
	}

	public void abreInclusaoTurno() {
		Map<String, Object> options = new HashMap<String, Object>();
		options.put("resizable", false);
		options.put("modal", true);
		options.put("closeable", false);
		RequestContext.getCurrentInstance().openDialog("editarTurno", options, null);
	}

	public void concluiEdicaoTurno(SelectEvent event) {
		listTurno = turnoService.buscarTodos();

		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Operação realizada com sucesso.", null);
		FacesContext.getCurrentInstance().addMessage(null, message);
	}

	public List<Turno> getListTurno() {
		return listTurno;
	}

	public void setListTurno(List<Turno> listTurno) {
		this.listTurno = listTurno;
	}

}
